use common_base::{prelude::*, LogConfig};
use common_core::CoreConfig;

use super::outer_v0::Config as OuterV0Config;

#[derive(Clone, Default, Debug, PartialEq, Eq)]
pub struct Config {
    pub cmd: String,
    pub config_file: String,

    pub core: CoreConfig,

    pub develop: DevelopConfig,

    pub log: LogConfig,
}

impl Config {
    pub fn load() -> Result<Self> {
        let cfg = OuterV0Config::load()?.try_into()?;

        Ok(cfg)
    }

    pub fn into_outer(self) -> OuterV0Config {
        OuterV0Config::from(self)
    }
}

#[derive(Clone, Debug, PartialEq, Eq)]
pub struct DevelopConfig {
    pub tenant_id: String,
    pub cluster_id: String,
    pub num_cpus: u64,

    pub http_handler_host: String,
    pub http_handler_port: u16,
    pub http_handler_result_timeout_millis: u64,
}

impl Default for DevelopConfig {
    fn default() -> Self {
        Self {
            tenant_id: "admin".to_owned(),
            cluster_id: "".to_owned(),
            num_cpus: 0,
            http_handler_host: "127.0.0.1".to_owned(),
            http_handler_port: 8000,
            http_handler_result_timeout_millis: 10000,
        }
    }
}
